import { Http,Headers,Jsonp, } from '@angular/http';
import { Injectable} from '@angular/core';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import * as moment from 'moment';
@Injectable()

export class MsgService{
    
    uurl = 'http://www.zhengshangfeng.xin';
    constructor(public http: Http,public jsonp:Jsonp,) {
        this.http = http;
    }
   
    getMsg(){
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.get(this.uurl + '/msg.php',{headers:headers});
    }

    postMsg(msg){
        let data = JSON.stringify({
            'userName':window.localStorage.getItem('userName'),
            'msg':msg,
            'time':moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
        })
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.post(this.uurl + '/pmsg.php',data,{headers:headers});
    }
}
